<template>
  <section class="choose-addres">
    <nav-bar>
      <div class="center" slot="center">选择地址</div>
    </nav-bar>
    <scroll class="scroll">
      <address-list
        :addresses="addresses"
        :is-mark="true"
        @click.native="handleSkipConfirmOrder"
        v-if="detectLogin"
      />
    </scroll>
    <div class="footer" @click="handleSkipAddAddress">
      <img src="~assets/img/confirmOrder/add_address.png" alt="" />
      <span>新增收货地址</span>
    </div>
    <router-view />
  </section>
</template>

<script>
import { detectLogin } from "common/mixin";

import Scroll from "components/common/betterScroll/Scroll";
import NavBar from "components/common/navbar/NavBar";

import AddressList from "components/content/address/AddressList";
export default {
  data() {
    return {
      currentIndex: 0,
    };
  },
  props: ["addresses"],
  inject: ["reload"],
  created() {
    if (this.detectLogin) {
      this.reload();
      this.$emit("obtainAddress");
    }
  },
  mixins: [detectLogin],
  methods: {
    handleSkipAddAddress() {
      this.$router.push("/confirmOrder/chooseAddress/addAddress");
    },
    handleSkipConfirmOrder() {
      this.$router.go(-1);
    },
  },

  components: {
    Scroll,
    NavBar,
    AddressList,
  },
};
</script>
<style  lang="less" scoped>
@import url("assets/css/mixin");
.choose-addres {
  background-color: #fff;
  .initial-children();
  .scroll {
    height: calc(100% - 44px - 45px);
    overflow: hidden;
  }
  .address-list {
    color: #333333;
    li {
      display: flex;
      align-items: center;
      padding: 20px;
      border-bottom: 1px solid #eaeaea;
      .svg {
        .check-mark();
        margin-right: 10px;
      }
      .right {
        flex: 1;
        .top {
          .name {
            font-weight: 700;
            font-size: 18px;
          }
          .appellation {
            margin: 0 10px 0 5px;
          }
        }
        .bottom {
          margin-top: 5px;
          .tag {
            padding: 3px;
            border-radius: 3px;
            margin-right: 5px;
            background-color: #ff5722;
            font-weight: 700;
            font-size: 10px;
            color: #fff;
          }
          .address-detail {
            font-size: 12px;
            color: #777777;
          }
        }
      }
    }
  }
  .footer {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    text-align: center;
    padding: 10px 0;
    font-size: 13px;
    color: #71b2ee;
    img {
      position: relative;
      top: -3px;
      width: 25px;
      height: 25px;
      margin-right: 5px;
      vertical-align: middle;
    }
  }
}
</style>